﻿using System;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using System.Collections.Generic;

namespace ExpressionSerialization
{
  [CollectionDataContract(ItemName = "ExpressionList")]
  public class XExpressionList:List<XExpression>
  {
    public XExpressionList() { }

    public XExpressionList(IEnumerable<Expression> expressions_)
    {
      foreach(var item in expressions_) {
        this.Add(XExpression.CreateFromExpression(item));
      }
    }

    //-----
    public Expression[] ToExpressions(Type dataContract_, System.Collections.Generic.List<ParameterExpression> parameters_)
    {
      Expression[] res = new Expression[this.Count];
      for(int i = 0; i < Count; i++) {
        res[i] = this[i].ToExpression(dataContract_, parameters_);
      }
      return res;
    }
  }
}
